package com.yanq.liancar.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.vondear.rxtool.RxActivityTool;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.SmallBOrderEvaluateActivity;
import com.yanq.liancar.bean.MessageModel;
import com.yanq.liancar.net.Net;
import com.yanq.liancar.util.Constant;
import com.yanq.liancar.view.recyclerview.RecyclerAdapter;
import com.yanq.liancar.view.recyclerview.RecyclerHolder;
import com.yanq.liancar.view.recyclerview.RecyclerListener;

import java.util.List;

public class MessageAdapter extends RecyclerAdapter<MessageModel.DataBean> implements RecyclerListener.OnClickListener<RecyclerHolder> {

    public MessageAdapter(Context context, List<MessageModel.DataBean> data) {
        super(context, data, R.layout.item_message);
    }

    @Override
    public void convert(RecyclerHolder holder, MessageModel.DataBean model) {
        TextView messageTitle = holder.findViewById(R.id.message_title);
        Button messageGo = holder.findViewById(R.id.message_go);
        holder.setTvText(R.id.message_time, model.getCreateDate());
        holder.setTvText(messageTitle, model.getTitle());
        holder.setTvText(R.id.message_content, model.getContent());
        if (mType != null && mType.equals(Constant.MSG_SYS)) {
            messageTitle.setVisibility(View.GONE);
        }
        switch (model.getStatus()) {
            case Constant.NO_BTN:
                messageGo.setVisibility(View.GONE);
                break;
            case Constant.HAS_BTN:
                switch (mType) {
                    case Constant.MSG_SYS:
                        messageGo.setText("升级版本");
                        break;
                    case Constant.MSG_BS:
                        messageGo.setText("立即接单");
                        break;
                    case Constant.MSG_CS:
                        messageGo.setText("评价");
                        break;
                }
                messageGo.setVisibility(View.VISIBLE);
                break;
        }

        holder.setOnClickListener(this, R.id.message_go);
    }

    @Override
    public void onClick(View v, int position, RecyclerHolder holder) {
        switch (mType) {
            case Constant.MSG_SYS: // 版本更新
                Net.checkVersion(mContext, true);
                break;
            case Constant.MSG_BS: // 立即接单
//                Bundle bundle=new Bundle();
//                RxActivityTool.skipActivity(mContext,dataBean.getUrl() );
                break;
            case Constant.MSG_CS: // 评价
                String url = mData.get(position).getUrl();
                Bundle bundle=new Bundle();
                bundle.putString("noNum",url);
                RxActivityTool.skipActivity(mContext, SmallBOrderEvaluateActivity.class,bundle);
                break;
        }
    }
}